﻿@{
    ViewBag.Title = "GoodsUpload";
}

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <style>
        body
        {
            padding-left:10px;
            font-size:13px;
        }
        h1
        {
            font-size:20px;
            font-family:Verdana;
        }
        h4
        {
            font-size:16px;
            margin-top:25px;
            margin-bottom:10px;
        }
        .d1 {
            position:relative;
            top:30px;
            left:20px;
        }
        .description
        {
            position:relative;
            top:30px;
            left:20px;
            padding-bottom:30px;
            font-family:Verdana;
        }
        .description h3
        {
            color:red;
            font-size:16px;
            margin:0 30px 10px 0px;
            padding:25px 0 8px;
            /*background:url(titleback.png) no-repeat scroll left bottom transparent*/
            border-bottom:solid 1px #888;
        }
    </style>   
    <script src="../scripts/boot.js" type="text/javascript"></script>
    <script src="../Scripts/ajaxfileupload.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server" method="post" style="height: 100%">
        <div class="d1">            
            <table style="margin-top:1px;">
                <tr>
                    @*<td width="60px" height ="30px" align="right">导入文件： </td>*@
                    <td width="400px" height ="30px" align="center">
                        @*<input class="mini-htmlfile" name="Fdata" limitType="*.xls;*.xlsx" id="file1" style="width:400px;"/>*@
                        <p><input type="file" id="file1" name="file" style="width:400px;" /></p>
                    </td>
                </tr>
             </table> 
            <table style="margin-top:10px;">
                <tr>
                    <td width="120px" height ="30px" align="center">
                        <input type="button" id="btn_inport" value="开始导入" style="width:100px;" onclick="ajaxFileUpload()"/>
                    </td>
                    <td width="120px" height ="30px" align="center">
                        <input type="button" value="下载模板" style="width:100px;" onclick="getUploadFile()"/>
                    </td>
                    <td width="120px" height ="30px" align="center">
                        <input type="button" value="结果查询" style="width:100px;" onclick="getUploadData()"/>
                    </td>
                    <td width="140px" height ="30px" align="left">
                        <div id="ckUpdateFlag" name="UpdateFlag" class="mini-checkbox" readOnly="false" text="对已存在的相同条码的商品进行覆盖"></div>
                    </td>
                    <td width="80px" height ="30px" align="right">验证口令：</td>
                    <td width="90px" height ="30px" align="center">
                        <input id="ActionCode"  type="password" class="form-control" placeholder="">
                    </td>                    
                </tr>
             </table>        
        </div>
        <div class="description" style="left:3px">
            <h3>提示: </h3>
            <span>
                1、内装数<font style="color:red"><strong>默认填1</strong></font>
                （除非一品多码例如一包烟和一条烟不同条码同一个产品编码换算，才需要在大包装条码的内装数输10，小包装的条码内装数还是填1.否则影响库存准确）<br>
                2、如果导入时间过长，可以用查询按钮进行查询导入结果。<br>
                3、不同的商品使用的编码必须不同，相同的商品编码将作为同一个商品的多规格来处理。<br>
                4、每次导入的商品数不能超过<font style="color:red"><strong>500</strong></font>条。
            </span>
        </div>   
        
        <div class="mini-fit" style="width:100%;height:70%;top:10px">
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:96%;left:0px" pageSize="15" fitColumns="false" 
                    borderStyle="border:1;" url="GetList" sortMode="client" showPager = "false">
                <div property="columns">
                    <div field="FNumber" name="FNumber" width="260" headeralign="center" allowsort="true">标题</div>
                    <div field="FName" name="FName" width="750" headeralign="center" allowsort="true">内容</div>
                </div>
            </div>
        </div>
</form>
</body>
<script>
    mini.parse();
    var grid = mini.get("datagrid1");
    var mTimestamp = "0";
    var mTickCount = 0;
    var uID = parent.window.getSystemAppID();

    function ajaxFileUpload() {
        if ($("#file1").val() == "") {
            alert("请选择Excel文档文件。");
            return;
        }
        $.ajax({
            url: '../Base/GetTimeStamp',
            data: { mSystemAppID: uID},
            dataType: 'text',
            async: false,
            success: function (text) {
                mTimestamp = text;
                setFileUpload();
            }
        });
    }

    function tick() {
        getUploadData();
    }

    function setFileUpload() {
        var FSystemAppID = parent.window.getSystemAppID();
        var sUpLoadTag = $("#ActionCode").val();
        var mUpdateFlag = "0";
        if (mini.getbyName("UpdateFlag").getChecked() == true) mUpdateFlag = "1";
        mini.mask({
            el: document.body,
            cls: 'mini-mask-loading',
            html: '正在导入，请稍后...'
        });
        $.ajaxFileUpload({            
            url: '/Upload/UploadGoods',
            fileElementId: 'file1',               //文件上传域的ID
            secureuri: false,
            data: { mSystemAppID: FSystemAppID, mUpdateFlag: mUpdateFlag, mTimestamp: mTimestamp, mUpLoadTag: sUpLoadTag }, //附加的额外参数
            dataType: 'json',                   //返回值类型 一般设置为json
            success: function (data, status)    //服务器成功响应处理函数
            {
                clearFile();
                tick();
            },
            error: function (data, status, e)   //服务器响应失败处理函数
            {
                mini.unmask(document.body);
                alert(data);
            },
            complete: function () {
                mini.unmask(document.body);
                clearFile();
            }
        });
    }

    function clearFile() {
        $('#file1').val('');
    }

    function getUploadData() {
        if (mTickCount > 29) mini.unmask(document.body);
        mTickCount += 1;
        $.ajax({
            url: '../Base/GetImportReport',
            data: { mSystemAppID: uID, sTimestamp: mTimestamp },
            dataType: 'text',
            async: false,
            success: function (text) {
                var dataR = mini.decode(text);
                grid.setData(dataR.datadetail);
                if (dataR.datadetail.length > 0) {
                    var rs = dataR.datadetail[0];
                    if (rs.FState == 0) {
                        if (mTickCount < 30) window.setTimeout("tick()", 5000);//1秒=1000
                    } else {
                        mini.unmask(document.body);
                        mini.getbyName("Fdata").setValue("");
                        mini.getbyName("Fdata").setText("");
                    }
                }
                else {
                    if (mTickCount < 30) window.setTimeout("tick()", 5000);//1秒=1000
                }
            }
        });
    }

    function getUploadFile() {
        var url = "../templet/goodsTemp.xls";
        window.open(url);
    }

</script>